import { InjectionKey } from 'vue'
import { createStore, useStore as baseUseStore, Store } from 'vuex'
import homeModule, { HomeStateType } from './modules/home'

export interface RootStateType {
  count: number,

}

interface AllStateType extends RootStateType {
    homeModule: HomeStateType
}

export const key: InjectionKey<Store<RootStateType>> = Symbol('vuex')

export const store = createStore<RootStateType>({
  state: {
    count: 0
  },
  modules: {
    homeModule
  }
})

// 定义自己的 `useStore` 组合式函数
export function useStore () {
  return baseUseStore<AllStateType>(key)
}
